package com.ssmk.module.shoppingcar.order;

import android.content.res.Resources;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ssmk.R;
import com.ssmk.base.MVPBaseActivity;
import com.ssmk.module.shoppingcar.adapter.AllOrderVpAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 我的订单界面
 */
public class AllOrderActivity extends MVPBaseActivity implements View.OnClickListener {

    @BindView(R.id.allorder_tab)
    TabLayout mAllorderTab;
    @BindView(R.id.allorder_vp)
    ViewPager mAllorderVp;
    @BindView(R.id.top_iv_back)
    ImageView mTopIvBack;
    @BindView(R.id.top_tv_title)
    TextView mTopTvTitle;
    private String[] mTitles = new String[]{"全部", "待付款", "待发货", "待收货", "售后"};

    @Override
    protected void initview() {
        Resources res = this.getResources();
        String title = res.getString(R.string.all_order);
        mTopTvTitle.setText(title);
        //得到当前的tab对应得position
        int orderState = getIntent().getIntExtra("orderState", 0);
        getTab(orderState);

        List<Fragment> list = new ArrayList<>();
        /*list.add(new AllOrder_Fragment_all());//全部
        list.add(new AllOrder_Fragment_pay());//待支付
        list.add(new AllOrder_Fragment_send());//待发货
        list.add(new AllOrder_Fragment_receive());//待收货
        list.add(new AllOrder_Fragment_sale());//售后*/
        for (int i = 0; i < mTitles.length; i++) {
            list.add(AllOrder_Fragment_all.getInstance(mTitles[i]));
        }

        mAllorderTab.setTabMode(TabLayout.MODE_FIXED);
        mAllorderTab.setupWithViewPager(mAllorderVp);
        mAllorderVp.setAdapter(new AllOrderVpAdapter(getSupportFragmentManager(), mTitles, list));

        mTopIvBack.setOnClickListener(this);//返回按钮
    }
    //显示position对应的vp页面
    private void getTab(int i) {
        TabLayout.Tab tab = mAllorderTab.getTabAt(i);
        if (tab != null) {
            mAllorderVp.setCurrentItem(i);
        }
    }

    @Override
    protected void initdata() {

    }

    @Override
    protected int layoutRes() {
        return R.layout.activity_all_order;
    }

    @Override
    public void UpData(Object o) {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_iv_back:
                finish();
                break;
        }
    }
}
